home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / CrashBurn.sit / Crash & Burn / source code / FireBugPPCTest.cpp < prev    next >
C/C++ Source or Header  |  1997-06-27  |  5KB  |  253 lines

  1. #include "patches.h"
  2. #include <traps.h>
  3. #include <lowmem.h>
  4.  
  5. #include <iostream>
  6. #include <qdoffscreen.h>
  7. #include "RectUtilities.h"
  8. #include "flames.h"
  9.  
  10.  
  11. // 16777216
  12.  
  13.  
  14. static     CGrafPort    gMyPort;
  15. static  FlameDataRecPtr    gFlames = NULL;
  16. static     FlameDataRecPtr    gFlames2 = NULL;
  17.  
  18.  
  19.  
  20.  
  21. static void LockHandle(Handle    h)
  22. {
  23.     if(h){
  24.         HLock(h);
  25.     }
  26. }
  27.  
  28. static void UnlockHandle(Handle h)
  29. {
  30.     if(h){
  31.         HUnlock(h);
  32.     }
  33. }
  34.  
  35. static void    UnlockPixMap(PixMapHandle p)
  36. {
  37.     if(p){
  38.         UnlockHandle((Handle)p);
  39.         UnlockHandle((Handle)p[0]->pmTable);
  40.     }
  41. }
  42.  
  43. static void    LockPixMap(PixMapHandle    p)
  44. {
  45.     if(p){
  46.         LockHandle((Handle)p);
  47.         LockHandle((Handle)p[0]->pmTable);
  48.     }
  49. }
  50.  
  51. static void    LockPixPat(PixPatHandle p)
  52. {
  53.     if(p){
  54.         LockHandle((Handle)p);
  55.         LockPixMap(p[0]->patMap);
  56.         LockHandle((Handle)p[0]->patData);
  57.         LockHandle((Handle)p[0]->patXData);
  58.         LockHandle((Handle)p[0]->patXMap);
  59.     }
  60. }
  61.  
  62. enum {
  63.     uppProcPtr = kPascalStackBased,
  64.     uppEntry = kPascalStackBased |
  65.         STACK_ROUTINE_PARAMETER(1,SIZE_CODE(sizeof(ProcPtr)))
  66. };
  67.  
  68. static long    gA5World;
  69. static long    g2Count;
  70.  
  71.  
  72. static Boolean        KeyIsDown(
  73.     short            theKeyCode)
  74. {
  75.     KeyMap            theKeys;
  76.     
  77.     GetKeys( theKeys);                    /* Get state of each key            */
  78.                                         
  79.         /* Ordering of bits in a KeyMap is truly bizarre. A KeyMap is a    */
  80.         /* 16-byte (128 bits) array where each bit specifies the start    */
  81.         /* of a key (0 = up, 1 = down). We isolate the bit for the        */
  82.         /* specified key code by first determining the byte position in    */
  83.         /* the KeyMap and then the bit position within that byte.        */
  84.         /* Key codes 0-7 are in the first byte (offset 0 from the        */
  85.         /* start), codes 8-15 are in the second, etc. The BitTst() trap    */
  86.         /* counts bits starting from the high-order bit of the byte.    */
  87.         /* For example, for key code 58 (the option key), we look at    */
  88.         /* the 8th byte (7 offset from the first byte) and the 5th bit    */
  89.         /* within that byte.                                            */
  90.         
  91.     return( BitTst( ((char*) &theKeys) + theKeyCode / 8,
  92.                     (long) 7 - (theKeyCode % 8) ) );
  93. }
  94.  
  95.  
  96. static pascal void _IdleProc()
  97. {
  98.     long    oldA5 = SetA5(gA5World);
  99.     
  100.     if(KeyIsDown(0x3B)){
  101.         StartFlames(gFlames2);
  102.     }
  103.     
  104.     g2Count++;
  105.     if( (g2Count % 100) == 0){
  106.         StepFlames(gFlames);
  107.         StepFlames(gFlames2);
  108.     }
  109.     SetA5(oldA5);    
  110. }
  111.  
  112.  
  113. static     void     DoMacsBug()
  114. {
  115.     gA5World = SetCurrentA5();
  116.     
  117.     Handle    h = Get1Resource('Code',0);
  118.     if(h != NULL){
  119.         HLock(h);    
  120.     
  121.         UniversalProcPtr callBack = NewRoutineDescriptor((ProcPtr)_IdleProc, uppProcPtr, GetCurrentISA());
  122.         CallUniversalProc((UniversalProcPtr)*h,uppEntry,callBack);
  123.         
  124.         Debugger();
  125.         
  126.         PaintBehind(NULL,GetGrayRgn());
  127.         PaintOne((WindowRef)FrontWindow(),FrontWindow()->visRgn);
  128.         DrawMenuBar();
  129.     
  130.     }
  131. }
  132.  
  133.  
  134. void main()
  135. {
  136.     cout << "Init" << endl;
  137.     
  138.     GDHandle    mainDevice = GetMainDevice();
  139.     
  140.     LockHandle((Handle)mainDevice);
  141.     LockPixMap(mainDevice[0]->gdPMap);
  142.     LockHandle((Handle)mainDevice[0]->gdITable);
  143.     LockHandle((Handle)mainDevice[0]->gdSearchProc);
  144.     LockHandle((Handle)mainDevice[0]->gdCompProc);
  145.  
  146.     
  147.     OpenCPort(&gMyPort);
  148.     SetPort((GrafPtr)&gMyPort);
  149.     BackColor(blackColor);
  150.     EraseRect(&gMyPort.portRect);
  151.     BackColor(whiteColor);
  152.     
  153.     Rect            macsBug;
  154.     Rect            screenRect;
  155.     SetRect(&macsBug,0,0,640,480);
  156.     SetRect(&screenRect,0,0,0x340,624);
  157.     Point            center;
  158.     
  159.     center.h = screenRect.right/2;
  160.     center.v = screenRect.bottom/2;
  161.     
  162.     RectUtil::CenterRectOnPoint(&macsBug,center);
  163.     RgnHandle        screenRgn = NewRgn();
  164.     RgnHandle        mbRgn = NewRgn();
  165.     
  166.     RectRgn(screenRgn,&screenRect);
  167.     RectRgn(mbRgn,&macsBug);
  168.     
  169.     DiffRgn(screenRgn,mbRgn,screenRgn);
  170.     
  171.     SetClip(screenRgn);
  172.  
  173.     
  174.     LockPixMap(gMyPort.portPixMap);
  175.     LockHandle((Handle)gMyPort.grafVars);
  176.     LockHandle((Handle)gMyPort.visRgn);
  177.     LockHandle((Handle)gMyPort.clipRgn);
  178.     LockPixPat(gMyPort.bkPixPat);
  179.     LockPixPat(gMyPort.pnPixPat);
  180.     LockPixPat(gMyPort.fillPixPat);
  181.  
  182.  
  183.                     double    fFadeRate = 0.02;
  184.                     double    fDensity = 0.5;    
  185.                     short    fMinWidth = 2;
  186.                     short    fMaxWidth = 4;                
  187.     
  188.     FlameDataRecPtr        f;
  189.  
  190.     
  191.     Rect                myRect;
  192.     Rect                topRect;
  193.     
  194.     topRect = macsBug;
  195.     topRect.bottom = topRect.top;
  196.     topRect.top -= 75;
  197.  
  198.     myRect = gMyPort.portRect;
  199.     myRect.top = myRect.bottom - 100;
  200. //    myRect.top = myRect.bottom - 50;
  201. //    myRect.right = myRect.left + 150;
  202. //    myRect.top = myRect.bottom - 100;
  203. //    myRect.left += 200;
  204. //    myRect.right -= 200;
  205.     
  206.  
  207.     myRect = gMyPort.portRect;
  208.     myRect.top = myRect.bottom - 100;
  209.     
  210.     f = MakeNewFlames ((GrafPtr)&gMyPort, &myRect,
  211.                                 fMinWidth,fMaxWidth,
  212.                                 fDensity, fFadeRate, 
  213.                                 30,GetCTable(1280));
  214.                                 
  215.     gFlames2 = MakeNewFlames ((GrafPtr)&gMyPort, &topRect,
  216.                                 fMinWidth,fMaxWidth,
  217.                                 fDensity, .04, 
  218.                                 30,GetCTable(1280));
  219.                                 
  220.     
  221.     myRect = gMyPort.portRect;
  222.     myRect.top = myRect.bottom - 100;
  223.     myRect.left = myRect.right - 150;
  224.     
  225.  
  226.  
  227.     LockFlames(f);
  228.     StartFlames (f);
  229.     
  230.     LockFlames(gFlames2);
  231. //    StartFlames(gFlames2);
  232.     g2Count = 0;
  233.  
  234.  
  235.     gFlames = f;
  236.  
  237.     DoMacsBug();
  238.  
  239.     FreeFlames(&f);
  240.     FreeFlames(&gFlames2);
  241.  
  242.     CloseCPort(&gMyPort);
  243.  
  244.  
  245.     UnlockHandle((Handle)mainDevice[0]->gdCompProc);
  246.     UnlockHandle((Handle)mainDevice[0]->gdSearchProc);
  247.     UnlockHandle((Handle)mainDevice[0]->gdITable);
  248.     UnlockPixMap(mainDevice[0]->gdPMap);
  249.     UnlockHandle((Handle)mainDevice);
  250.     
  251. }
  252.  
  253.